#if !defined(WEBBY_FASTCGI_HXX)
#define WEBBY_FASTCGI_HXX

#include <map>
#include <string>
#include <iostream>

namespace webby
{

	class FastCGI
	{
	public:
		FastCGI( unsigned int short id ) : mID( id ), mVersion(1), mType(UNKNOWN), mRequestID(0), mContentLength(0), mPaddingLength(0), mReserved(0), mFlags(FLAGS_UNKNOWN) { std::cout << "ID is " << mID; }
		enum MessageType
		{
			BEGIN_REQUEST = 1,
			ABORT_REQUEST = 2,
			END_REQUEST = 3,
			PARAMS = 4,
			STDIN = 5,
			STDOUT = 6,
			STDERR = 7,
			DATA = 8,
			GET_VALUES = 9,
			GET_VALUES_RESULT = 10,
			UNKNOWN = 11,
			MAX = 12
		};

		enum RoleType
		{
			ROLE_UNKNOWN = 0,
			RESPONDER = 1,
			AUTHORIZER = 2,
			FILTER = 3
		};	

		enum Flags
		{
			FLAGS_UNKNOWN = 0,
			KEEP_CONNECTION = 1
		};

		unsigned short mID;
		unsigned char mVersion;
		MessageType mType;
		unsigned short mRequestID;
		unsigned short mContentLength;
		unsigned char mPaddingLength;
		unsigned char mReserved;

		Flags mFlags;	
		RoleType mRole;

		void makeBeginRequest();

		unsigned int mLength;
		unsigned char mBuffer[2000];

		std::map< std::string, std::string > mParams;
		void encodeParam( const std::string &name, const std::string &value );	
		void makeStdIn();
	};

}

#endif
